package com.kucai.yifaqapp.ui.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.kucai.yifaqapp.R;
import com.kucai.yifaqapp.dagger.component.fragment.DaggerLauncherViewPagerHomeFragmentComponent;
import com.kucai.yifaqapp.dagger.module.fragment.LauncherViewPagerHomeFragmentModule;
import com.kucai.yifaqapp.global.Info;
import com.kucai.yifaqapp.model.network.entity.res.IsHasQipaiBean;
import com.kucai.yifaqapp.model.network.entity.res.ResActivity;
import com.kucai.yifaqapp.model.network.entity.res.ResActivitys;
import com.kucai.yifaqapp.model.network.entity.res.ResBanner;
import com.kucai.yifaqapp.model.network.entity.res.ResKaiyuanGame;
import com.kucai.yifaqapp.model.network.entity.res.ResNotices;
import com.kucai.yifaqapp.presenter.fragment.LauncherViewPagerHomeFragmentPresenter;
import com.kucai.yifaqapp.ui.activity.ActivityDetails;
import com.kucai.yifaqapp.ui.activity.AllActivity;
import com.kucai.yifaqapp.ui.activity.AlllotteryActivity;
import com.kucai.yifaqapp.ui.activity.BaseActivity;
import com.kucai.yifaqapp.ui.activity.GameDetailActivityFinal;
import com.kucai.yifaqapp.ui.activity.LoginActivity;
import com.kucai.yifaqapp.ui.activity.RegisterActivity;
import com.kucai.yifaqapp.ui.activity.WebActivity;
import com.kucai.yifaqapp.ui.activity.WebActivityGame;
import com.kucai.yifaqapp.ui.view.ViewPagerHomeView;
import com.kucai.yifaqapp.util.BannerLayout;
import com.kucai.yifaqapp.util.EventBus.GameDetailConstances;
import com.kucai.yifaqapp.util.EventBus.refreshFragmentEvent;
import com.kucai.yifaqapp.util.GlideImageLoader;
import com.kucai.yifaqapp.util.OnItemClickListener;
import com.kucai.yifaqapp.util.SYSOUtils;
import com.kucai.yifaqapp.util.SpUtils;
import com.kucai.yifaqapp.widget.AlertDialogIos;
import com.kucai.yifaqapp.widget.AlertDialogIos1;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.OnClick;


/**
 * 大厅
 */
public class LauncherViewPagerHomeFragment extends BaseFragment<LauncherViewPagerHomeFragmentPresenter>
        implements ViewPagerHomeView {
    @BindView(R.id.skinbg)
    LinearLayout skinbg;
    @BindView(R.id.back)
    ImageView back;
    @BindView(R.id.login_bt)
    Button loginBt;
    @BindView(R.id.rigist_bt)
    Button rigistBt;
    @BindView(R.id.pelay_bt)
    Button pelayBt;
    @BindView(R.id.more_tv)
    TextView moreTv;
    @BindView(R.id.home_rl)
    RecyclerView homeRl;
    @BindView(R.id.game_bt1)
    TextView gameBt1;
    @BindView(R.id.game_bt2)
    TextView gameBt2;
    @BindView(R.id.game_list)
    RecyclerView gameList;
    @BindView(R.id.activity_lin)
    LinearLayout activityLin;
    @BindView(R.id.banner)
    BannerLayout banner;
    @BindView(R.id.mMarqueeView)
    TextView mMarqueeView;
    @BindView(R.id.left_bt_iv)
    ImageView leftBtIv;
    @BindView(R.id.left_bt)
    RelativeLayout leftBt;
    @BindView(R.id.right_bt_iv)
    ImageView rightBtIv;
    @BindView(R.id.right_bt)
    RelativeLayout rightBt;
    @BindView(R.id.scrow_text)
    LinearLayout scrowText;
    @BindView(R.id.scrow_text_lin)
    View scrowTextLin;
    @BindView(R.id.game_bt)
    LinearLayout gameBt;
    @BindView(R.id.game_btlin)
    RelativeLayout gameBtlin;
    @BindView(R.id.login_lin)
    LinearLayout loginlin;
    @BindView(R.id.login_lins)
    LinearLayout loginlins;//已登录
    @BindView(R.id.youke)
    TextView youke;//用户名
    @BindView(R.id.exitbt)
    TextView exitbt;//用户名
    @BindView(R.id.qipailist)
    RecyclerView qipailist;//用户名

    Boolean popflag = true;
    private ActivtyAdapter activtyAdapter;
    private Adapter adapter;
    private Adapter2 adapter2;
    private Adapter1 adapter1;
    private String url;
    private ArrayList<ResBanner.DataBeanX.GamesBean> gamedata = new ArrayList<>();//左侧游戏
    private ArrayList<ResActivity.DataBeanX.SlideListBean> bannerdata = new ArrayList<>();//banner
    private ArrayList<ResNotices.DataBeanX.DataBean> addata = new ArrayList<>();//广告
    private ArrayList<ResBanner.DataBeanX.NoticesBean> noticedata = new ArrayList<>();//滚动字
    private ArrayList<ResActivity.DataBeanX.ActivityBean.DataBean> slidedata = new ArrayList<>();//活动
    private int a = 0;//滚动字标记
    private int flag;//右侧游戏加载标记 1==开元  2==龙城  3==无双 4==vg
    private int activitysize;//活动几条显示控制
    private String serverurl;//在线客服
    //热门彩票数据  写死十一个
    int[] leftimg = {R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher,
            R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.left_j,
            R.mipmap.leftk};

    //开元棋牌游戏字库
    String[] kaiyuantv = {"德州扑克", "二八杠", "抢庄牛牛", "炸金花", "三公", "押庄龙虎", "21点", "通比牛牛", "极速炸金花",
            "抢庄牌九", "十三水", "百家乐", "幸运五张", "斗地主", "射龙门"};

    //开元棋牌URLTAG
    String[] kaiyuantag = {"dzpk", "ebg", "qznn", "zjh", "sg", "yzlh", "21d", "tbnn", "jszjh",
            "qzpj", "sss", "bjl", "xywz", "ddz", "slm"};
    //开元棋牌游戏图片
    int[] kaiyuanimg = {R.mipmap.dezhou, R.mipmap.erbagang, R.mipmap.qiangzhuang, R.mipmap.zhajinhua, R.mipmap.sangong,
            R.mipmap.yazhuanglonghu, R.mipmap.ershiyi, R.mipmap.tongbiniuniu, R.mipmap.jisuzhajinhua, R.mipmap.qiangzhuangpaijiu
            , R.mipmap.shisanshui, R.mipmap.baijiale, R.mipmap.xingyunwuzhang, R.mipmap.doudizhu, R.mipmap.shelongmen};

    //龙城棋牌游戏字库
    String[] longchengtv = {"抢庄牛牛", "龙虎斗", "二八杠", "百家乐", "通比牛牛", "三公", "炸金花", "斗地主", "牌九"};
    String[] longchengurl = {"qznn", "lhd", "ebg", "bjl", "tbnn", "sg", "zjh", "ddz", "pj"};
    //龙城棋牌游戏图片
    int[] longchengimg = {R.mipmap.lcqiangzhuangniuniu, R.mipmap.lclonghudou, R.mipmap.lcerbagang, R.mipmap.lcbaijiale, R.mipmap.lctongbiniuniu,
            R.mipmap.lcsangong, R.mipmap.lczhajinhua, R.mipmap.lcdoudizhu, R.mipmap.lcpaijiu};

    //龙城棋牌游戏字库
    String[] wushuangtv = {"百家乐", "无双捕鱼", "无双港五", "金皇港", "牛牛", "时时彩梭哈", "时时彩牛牛", "通比牛牛", "炸金花"};
    //龙城棋牌游戏图片
    int[] wushuangimg = {R.mipmap.wsbaijiale, R.mipmap.wsbuyu, R.mipmap.wsgangwu, R.mipmap.wsjinhuangguan, R.mipmap.wsniuniu,
            R.mipmap.wssuoha, R.mipmap.wssscniuniu, R.mipmap.wstbniuniu, R.mipmap.wszhajinhua};
    //VG棋牌字库
    String[] vgtv = {"推筒子", "十三水", "百人牛牛", "抢庄牛牛", "龙王捕鱼", "多财多福", "斗地主", "保险楚汉德州", "炸金花", "竞咪楚汉德州",
            "血战麻将", "加倍斗地主", "必下德州", "百人三公", "开心摇摇乐", "通比牛牛"};

    int[] vgiv = {R.mipmap.vgtuitongzi, R.mipmap.vgshisanshui, R.mipmap.vgniuniu, R.mipmap.vgqiangzhuang, R.mipmap.vg_longwang, R.mipmap.vgduocaiduofu, R.mipmap.vgdoudizhu,
            R.mipmap.vgbaoxian, R.mipmap.vgzhajinhua, R.mipmap.vgjingmi, R.mipmap.vgxuezhan, R.mipmap.vgjiabeidoudizhu, R.mipmap.bixiadezhou
            , R.mipmap.vgbairensangong, R.mipmap.vg_kxyyl, R.mipmap.vg_tbnn};

    String[] vgtag = {"8", "15", "4", "3", "5", "6", "1", "10", "12", "7", "11", "9", "13", "14", "19", "20"};
    private AlertDialogIos myDialog;
    private AlertDialogIos1 myDialog1;
    private ResBanner.DataBeanX.GamesBean mgamedatas;

    @Override
    protected int setContentView() {
        return R.layout.fragment_home;
    }

    @Override
    protected void initDagger() {
        DaggerLauncherViewPagerHomeFragmentComponent.builder()
                .launcherViewPagerHomeFragmentModule(new LauncherViewPagerHomeFragmentModule(this))
                .build().inject(this);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        try {
            if (!EventBus.getDefault().isRegistered(this)) {
                EventBus.getDefault().register(LauncherViewPagerHomeFragment.this);
            }
            if (Info.user == null) {
                loginlin.setVisibility(View.VISIBLE);
                loginlins.setVisibility(View.GONE);
            } else {
                loginlin.setVisibility(View.GONE);
                loginlins.setVisibility(View.VISIBLE);
                if (Info.user.userName != null) {
                    youke.setText(Info.user.userName);
                }
            }
            //获取首页信息
            mPresenter.getbanner();
            //获取活动信息
            mPresenter.getactivity();
            InitView();

            mMarqueeView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    try {
                        myDialog1 = new AlertDialogIos1(getActivity()).builder();
                        myDialog1.setCancelable(false);
                        myDialog1.setGone().setTitle(noticedata.get(a).title).setMsg(noticedata.get(a).content).
                                setNegativeButton("取消", R.color.skyblue, new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
                                        myDialog1.dismiss();
                                    }
                                }).setPositiveButton("确定", R.color.skyblue, new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                myDialog1.dismiss();
                            }
                        }).show();


                    } catch (Exception e) {

                    }
                }
            });
        }catch (Exception e){
            Log.e("xdh","错误"+e.toString());
        }
    }

    private void InitView() {
        //禁止滑动
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false) {
            @Override
            public boolean canScrollVertically() {
                return false;
            }
        };
        //添加布局管理器
        homeRl.setLayoutManager(linearLayoutManager);
        //创建适配器
        homeRl.setHasFixedSize(true);
        homeRl.setNestedScrollingEnabled(false);
        activtyAdapter = new ActivtyAdapter();

        //禁止滑动
        GridLayoutManager gridLayoutManager = new GridLayoutManager(getContext(), 3) {
            @Override
            public boolean canScrollVertically() {
                return false;
            }
        };
        //添加布局管理器
        gameList.setLayoutManager(gridLayoutManager);
        gameList.setHasFixedSize(true);
        gameList.setNestedScrollingEnabled(false);
        //创建适配器
        adapter = new Adapter();
        adapter1 = new Adapter1();

    }

    @OnClick({R.id.exitbt, R.id.left_bt, R.id.right_bt, R.id.login_bt, R.id.rigist_bt, R.id.pelay_bt, R.id.more_tv})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.left_bt:
                gameBtlin.setVisibility(View.GONE);
                rightBt.setBackgroundColor(getContext().getResources().getColor(R.color.title_back));
                leftBt.setBackgroundColor(getContext().getResources().getColor(R.color.transparent_background));
                Glide.with(getContext()).load(R.mipmap.right_btb).into(rightBtIv);
                Glide.with(getContext()).load(R.mipmap.left_bt).into(leftBtIv);
                gameBt1.setTextColor(getContext().getResources().getColor(R.color.settingbg));
                gameBt2.setTextColor(getContext().getResources().getColor(R.color.colorTextBlack));
                //左边
                gameList.setAdapter(adapter);
                adapter.notifyDataSetChanged();
                break;
            case R.id.right_bt:
                boolean ishasqipai = false;
                int k = 0;
                for (int j = 0; j < mresBanner.data.games.size(); j++) {
                    if (mresBanner.data.games.get(j).code.equals("qpxy")) {
                        ishasqipai = true;
                        k = j;
                    }
                }
                mgamedatas = mresBanner.data.games.get(k);
                if (ishasqipai) {
                    gameBtlin.setVisibility(View.VISIBLE);
                    //设置游戏名字list
                    //设置adapter
                    LinearLayoutManager ms = new LinearLayoutManager(getActivity());
                    ms.setOrientation(LinearLayoutManager.HORIZONTAL);// 设置 recyclerview 布局方式为横向布局
                    qipailist.setLayoutManager(ms);
                    //首先将第一个设置为点击状态
                    for (int x = 0; x < mgamedatas.data.size(); x++) {
                        if (x == 0) {
                            mgamedatas.data.get(x).ischoose = true;
                            if (mgamedatas.data.get(0).g_id.equals("15")) {
                                flag = 1;
                            } else if (mgamedatas.data.get(0).g_id.equals("16")) {
                                flag = 2;
                            } else if (mgamedatas.data.get(0).g_id.equals("17")) {
                                flag = 3;
                            } else if (mgamedatas.data.get(0).g_id.equals("18")) {
                                flag = 4;
                            }
                        } else {
                            mgamedatas.data.get(x).ischoose = false;
                        }
                    }
                    adapter2 = new Adapter2();
                    qipailist.setAdapter(adapter2);
                }

                leftBt.setBackgroundColor(getContext().getResources().getColor(R.color.title_back));
                rightBt.setBackgroundColor(getContext().getResources().getColor(R.color.transparent_background));
                Glide.with(getContext()).load(R.mipmap.right_bt).into(rightBtIv);
                Glide.with(getContext()).load(R.mipmap.left_btb).into(leftBtIv);
                gameBt2.setTextColor(getContext().getResources().getColor(R.color.settingbg));
                gameBt1.setTextColor(getContext().getResources().getColor(R.color.colorTextBlack));
                //获取右侧游戏
                gameList.setAdapter(adapter1);
                adapter1.notifyDataSetChanged();
                break;
            case R.id.login_bt:
                startActivity(new Intent(getContext(), LoginActivity.class));
                break;
            case R.id.rigist_bt:
                startActivity(new Intent(getContext(), RegisterActivity.class));
                break;
            //试玩
            case R.id.pelay_bt:
                mPresenter.logindemo();
                break;
            //退出
            case R.id.exitbt:
                myDialog = new AlertDialogIos(getActivity()).builder();
                myDialog.setGone().setMsg("您确定退出游戏吗？").setNegativeButton("取消", R.color.skyblue, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        myDialog.dismiss();
                    }
                }).setPositiveButton("确定", R.color.skyblue, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        myDialog.dismiss();
                        //退出接口不带任何参数。所以认为没用，直接不访问，清楚本地登录状态
                        Toast.makeText(getContext(), "退出成功", Toast.LENGTH_SHORT).show();
                        Info.user = null;
                        SpUtils.clearUser(getContext());
                        loginlin.setVisibility(View.VISIBLE);
                        loginlins.setVisibility(View.GONE);
                    }
                }).show();
                break;
            case R.id.more_tv:
//                Toast.makeText(getContext(), "更多活动", Toast.LENGTH_SHORT).show();
                if (Info.user != null) {
                    if (Info.user.userName != null) {
                        startActivity(new Intent(getContext(), AllActivity.class));
                    } else {
                        startActivity(new Intent(getContext(), AllActivity.class));
                        Toast.makeText(getContext(), "请注册为正式账号", Toast.LENGTH_LONG).show();
                    }
                } else {
                    ((BaseActivity) getActivity()).startLogin();
                }
                break;
        }
    }

    @Override
    public void demologin() {
        //游客登录成功
        if (Info.user != null) {
            Toast.makeText(getContext(), "登录成功", Toast.LENGTH_SHORT).show();
            loginlin.setVisibility(View.GONE);
            loginlins.setVisibility(View.VISIBLE);
            youke.setText("游客");
        } else {
            Toast.makeText(getContext(), "游客登录失败了", Toast.LENGTH_SHORT).show();
        }
    }

    private ResBanner mresBanner;

    @Override
    public void getBanner(ResBanner resBanner) {
        try {
            if (resBanner.code == 0 && null != resBanner.data) {
                mresBanner = resBanner;
                //左侧游戏
                if (resBanner.data.games != null && resBanner.data.games.size() != 0) {

                    gamedata.clear();
                    for (int i = 0; i < resBanner.data.games.size(); i++) {
                        if (!resBanner.data.games.get(i).game_name.equals("棋牌游戏")) {
                            if (resBanner.data.games.get(i).game_id == 80 || resBanner.data.games.get(i).game_id == 50 ||
                                    resBanner.data.games.get(i).game_id == 82 || resBanner.data.games.get(i).game_id == 99 ||
                                    resBanner.data.games.get(i).game_id == 81 || resBanner.data.games.get(i).game_id == 1 ||
                                    resBanner.data.games.get(i).game_id == 4 || resBanner.data.games.get(i).game_id == 91 ||
                                    resBanner.data.games.get(i).game_id == 90 || resBanner.data.games.get(i).game_id == 66 ||
                                    resBanner.data.games.get(i).game_id == 65 || resBanner.data.games.get(i).game_id == 86 ||
                                    resBanner.data.games.get(i).game_id == 10 || resBanner.data.games.get(i).game_id == 12 ||
                                    resBanner.data.games.get(i).game_id == 13 || resBanner.data.games.get(i).game_id == 16 ||
                                    resBanner.data.games.get(i).game_id == 15 || resBanner.data.games.get(i).game_id == 18 ||
                                    resBanner.data.games.get(i).game_id == 11 || resBanner.data.games.get(i).game_id == 60 ||
                                    resBanner.data.games.get(i).game_id == 61 || resBanner.data.games.get(i).game_id == 21 ||
                                    resBanner.data.games.get(i).game_id == 70 || resBanner.data.games.get(i).game_id == 85 ||
                                    resBanner.data.games.get(i).game_id == 113 || resBanner.data.games.get(i).game_id == 55
                                    || resBanner.data.games.get(i).game_id == 801 || resBanner.data.games.get(i).game_id == 901
                                    || resBanner.data.games.get(i).game_id == 802 || resBanner.data.games.get(i).game_id == 902
                                    || resBanner.data.games.get(i).game_id == 803 || resBanner.data.games.get(i).game_id == 903
                                    || resBanner.data.games.get(i).game_id == 804 || resBanner.data.games.get(i).game_id == 904
                                    ) {
                                gamedata.add(resBanner.data.games.get(i));
                            }
                        }
                    }
                    gameList.setAdapter(adapter);
                    adapter.notifyDataSetChanged();
                }
                SYSOUtils.sOut_("滚动字" + resBanner.data.notices + resBanner.data.notices.size());
                //滚动字
                if (resBanner.data.notices != null && resBanner.data.notices.size() != 0) {
                    noticedata.clear();
                    noticedata.addAll(resBanner.data.notices);
                    mMarqueeView.setText(noticedata.get(a).content + "                 " + noticedata.get(a).content + "                 " + noticedata.get(a).content);
                    mMarqueeView.setSelected(true);
//                mMarqueeView.startScroll();
                    //如果不需要更新那么开始弹窗  因为先创建的在最下面，所以在其他人看来是反的
//                    for (int i = 0; i < resBanner.data.notices.size(); i++) {
                    SYSOUtils.sOut_("SHOUCI弹框" + resBanner.data.notices);
                    for (int i = resBanner.data.notices.size(); i > 0; i--) {
                        myDialog1 = new AlertDialogIos1(getActivity()).builder();
                        myDialog1.setCancelable(false);
                        myDialog1.setGone().setTitle(noticedata.get(i - 1).title).setMsg(noticedata.get(i - 1).content).
                                setNegativeButton("取消", R.color.skyblue, new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
                                        myDialog1.dismiss();
                                    }
                                }).setPositiveButton("确定", R.color.skyblue, new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                myDialog1.dismiss();
                            }
                        }).show();

                    }


                }

                boolean ishasqipai = false;
                for (int j = 0; j < mresBanner.data.games.size(); j++) {
                    if (mresBanner.data.games.get(j).code.equals("qpxy")) {
                        ishasqipai = true;
                    }
                }
                if (!ishasqipai) {
                    IsHasQipaiBean.ishasqipai = false;
                    rightBt.setVisibility(View.GONE);
                } else {
                    IsHasQipaiBean.ishasqipai = true;
                    rightBt.setVisibility(View.VISIBLE);
                }
            }
        } catch (Exception e) {

        }
    }

    @Override
    public void getActivity(ResActivity resActivity) {
        activitysize = resActivity.data.activity.num;
        //客服
        if (resActivity.data.onlineSer != null) {
            serverurl = resActivity.data.onlineSer + "";
            Info.seviceurl = serverurl;
        }
        //活动

        if (resActivity.data.activity.data != null) {
            slidedata.clear();
            slidedata.addAll(resActivity.data.activity.data);
            homeRl.setAdapter(activtyAdapter);
            activtyAdapter.notifyDataSetChanged();
        }
        //banner
        if (null != resActivity.data.slideList && resActivity.data.slideList.size() != 0) {
            bannerdata.clear();
            bannerdata.addAll(resActivity.data.slideList);
            banner.setImageLoader(new GlideImageLoader());
            banner.setViewUrls(bannerdata);
        }
        //  1开启 0关闭 聊天室
        if ((resActivity.data.chat_open + "").equals("1")) {
            IsHasQipaiBean.ishasChat = true;
        } else {
            IsHasQipaiBean.ishasChat = false;
        }
        //是否有红包
        try {
//            if (resActivity.data.hbUrl != null) {
//                if (resActivity.data.hbUrl instanceof String) {
//                    if (!(resActivity.data.hbUrl + "").isEmpty()) {
//                        //显示红包
//                        Intent intent = new Intent(getActivity(), shouyehbdialog.class);
//                        intent.putExtra("hb_url", HttpAdress.getuseAdress1() + resActivity.data.hbUrl + "");
//                        startActivity(intent);
//                    }
//                } else {
//
//                }
//            }
        } catch (Exception e) {
            Log.e("xdh",e.toString());
        }
    }

    @Override
    public void getActivitys(ResActivitys resActivitys) {
        if (resActivitys.data.type.equals("fuwenben")) {
            Intent intent = new Intent(getContext(), WebActivity.class);
            Bundle bundle = new Bundle();
            SYSOUtils.sOut_(resActivitys.data);
            bundle.putString("content", resActivitys.data.doc);
            bundle.putString("title", resActivitys.data.title);
            intent.putExtras(bundle);
            startActivity(intent);
        }
    }

    @Override
    public void getGames(ResKaiyuanGame resKaiyuanGame) {
//        String url = resKaiyuanGame.data.url;
        Intent intent = new Intent(getContext(), WebActivityGame.class);
        Bundle bundle = new Bundle();
        bundle.putString("url", resKaiyuanGame.data.url);
        bundle.putString("title", "空");
        intent.putExtras(bundle);
        startActivity(intent);
    }

    public int count = 0;

    public void onErrorCustom() {
        count = count + 1;
        if (count == 1) {
            //弹窗确定之后  请求接口
            AlertDialogIos myDialog = new AlertDialogIos(getActivity()).builder();
            myDialog.setGone().setMsg("当前网络差，是否重新请求数据").setNegativeButton("取消", R.color.skyblue, new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    myDialog.dismiss();
                }
            }).setPositiveButton("确定", R.color.skyblue, new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    myDialog.dismiss();
                    mPresenter.getbanner();
                    mPresenter.getactivity();
                }
            }).show();
        } else {
            count = 0;
        }
    }

    //登录成功弹框
    public void loginNotices(ResNotices resNotices) {
        addata.clear();
        addata.addAll(resNotices.data.data);
//        SYSOUtils.sOut_("denglde登录弹框" + addata);2
//        for (int i = addata.size(); i > 0; i--) {
//        }
        for (int i = addata.size(); i > 0; i--) {

            myDialog1 = new AlertDialogIos1(getActivity()).builder();
            myDialog1.setCancelable(false);
            myDialog1.setGone().setTitle(addata.get(i - 1).title).setMsg(addata.get(i - 1).content).
                    setNegativeButton("取消", R.color.skyblue, new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            myDialog1.dismiss();
                        }
                    }).setPositiveButton("确定", R.color.skyblue, new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    myDialog1.dismiss();
                }
            }).show();

        }

    }

    /////////////////////////////////////////////////////////////////////////////////////////////////
    class ActivtyAdapter extends RecyclerView.Adapter<ActivtyAdapter.MViewHolder>
            implements OnItemClickListener {
        @Override
        public MViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            return new MViewHolder(LayoutInflater.from(getContext())
                    .inflate(R.layout.activty_item, parent, false));

        }

        @Override
        public void onBindViewHolder(final MViewHolder holder, final int position) {
            if (null == slidedata.get(position).title) {
                holder.activity_tv.setVisibility(View.GONE);
            } else {
                holder.activity_tv.setVisibility(View.VISIBLE);
                holder.activity_tv.setText(slidedata.get(position).title + "");

            }
            Glide.with(getContext())
                    .load(slidedata.get(position).img)
                    .override(414, 100)
                    .into(holder.activity_iv);
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (null != Info.user) {
                        if (null == Info.user.userName) {
                            Toast.makeText(getContext(), "请注册为正式账号", Toast.LENGTH_SHORT).show();
                        }
                        if (slidedata.get(position).type.equals("fuwenben")) {
                            mPresenter.getactivitys(slidedata.get(position).doc, slidedata.get(position).imgid);
                        } else if (slidedata.get(position).type.equals("guanfang")) {
                            Intent intent = new Intent(getContext(), ActivityDetails.class);
                            intent.putExtra("id", slidedata.get(position).id + "");
                            intent.putExtra("doc", slidedata.get(position).doc + "");
                            intent.putExtra("activitytype", slidedata.get(position).id + "");
                            startActivity(intent);

                        } else if (slidedata.get(position).type.equals("tanchuang")) {
                            myDialog1 = new AlertDialogIos1(getActivity()).builder();
                            myDialog1.setCancelable(false);
                            myDialog1.setGone().setTitle(slidedata.get(position).title + "").setMsg(slidedata.get(position).content + "").
                                    setNegativeButton("取消", R.color.skyblue, new View.OnClickListener() {
                                        @Override
                                        public void onClick(View v) {
                                            myDialog1.dismiss();
                                        }
                                    }).setPositiveButton("确定", R.color.skyblue, new View.OnClickListener() {
                                @Override
                                public void onClick(View v) {
                                    myDialog1.dismiss();
                                }
                            }).show();
                        }
                    } else {
                        ((BaseActivity) getActivity()).startLogin();
                    }
                }
            });
        }

        @Override
        public int getItemCount() {
            return activitysize;
        }

        @Override
        public void onItemClick(View view, int position) {

        }

        class MViewHolder extends RecyclerView.ViewHolder {
            TextView activity_tv;
            ImageView activity_iv;

            MViewHolder(View itemView) {
                super(itemView);
                activity_tv = (TextView) itemView.findViewById(R.id.activity_tv);
                activity_iv = (ImageView) itemView.findViewById(R.id.activity_iv);

            }
        }
    }

    ////////////////////////////////////////////左侧游戏/////////////////////////////////////////////////////
    class Adapter extends RecyclerView.Adapter<Adapter.MViewHolder>
            implements OnItemClickListener {
        @Override
        public MViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            return new MViewHolder(LayoutInflater.from(getContext())
                    .inflate(R.layout.game_item, parent, false));

        }

        @Override
        public void onBindViewHolder(final MViewHolder holder, final int position) {

            if (gamedata.size() >= 7 && position == 7 && gamedata.size() < 10) {
                holder.geme_tv.setText("全部彩票");
                Glide.with(getContext()).load(R.mipmap.left_j).into(holder.game_iv);
                holder.itemView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        startActivity(new Intent(getContext(), AlllotteryActivity.class));
                    }
                });
            } else if (gamedata.size() >= 7 && position == 8 && gamedata.size() < 10) {
                holder.geme_tv.setText("在线客服");
                Glide.with(getContext()).load(R.mipmap.leftk).into(holder.game_iv);
                holder.itemView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (serverurl != null) {
                            Intent intent = new Intent(getContext(), WebActivity.class);
                            Bundle bundle = new Bundle();
                            bundle.putString("url", serverurl);
                            bundle.putString("title", "在线客服");
                            intent.putExtras(bundle);
                            startActivity(intent);
                        }
                    }
                });
            } else if (gamedata.size() >= 10 && gamedata.size() < 13 && position == 10) {
                holder.geme_tv.setText("全部彩票");
                Glide.with(getContext()).load(R.mipmap.left_j).into(holder.game_iv);
                holder.itemView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        startActivity(new Intent(getContext(), AlllotteryActivity.class));
                    }
                });
            } else if (gamedata.size() >= 10 && gamedata.size() < 13 && position == 11) {
                holder.geme_tv.setText("在线客服");
                holder.itemView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (serverurl != null) {
                            Intent intent = new Intent(getContext(), WebActivity.class);
                            Bundle bundle = new Bundle();
                            bundle.putString("url", serverurl);
                            bundle.putString("title", "在线客服");
                            intent.putExtras(bundle);
                            startActivity(intent);
                        }
                    }
                });
            } else if (gamedata.size() < 7 && position == gamedata.size()) {
                holder.geme_tv.setText("全部彩票");
                Glide.with(getContext()).load(R.mipmap.left_j).into(holder.game_iv);
                holder.itemView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        startActivity(new Intent(getContext(), AlllotteryActivity.class));
                    }
                });
            } else if (gamedata.size() < 7 && position == gamedata.size() + 1) {
                if (position == gamedata.size() + 1) {
                    holder.geme_tv.setText("在线客服");
                    Glide.with(getContext()).load(R.mipmap.leftk).into(holder.game_iv);
                    holder.itemView.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            if (serverurl != null) {
                                Intent intent = new Intent(getContext(), WebActivity.class);
                                Bundle bundle = new Bundle();
                                bundle.putString("url", serverurl);
                                bundle.putString("title", "在线客服");
                                intent.putExtras(bundle);
                                startActivity(intent);
                            }
                        }
                    });
                }
            } else if (gamedata.size() >= 13 && position == 13) {
                holder.geme_tv.setText("全部彩票");
                Glide.with(getContext()).load(R.mipmap.left_j).into(holder.game_iv);
                holder.itemView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        startActivity(new Intent(getContext(), AlllotteryActivity.class));
                    }
                });
            } else if (gamedata.size() >= 13 && position == 14) {
//                if (position == gamedata.size() + 1) {
                holder.geme_tv.setText("在线客服");
                Glide.with(getContext()).load(R.mipmap.leftk).into(holder.game_iv);
                holder.itemView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (serverurl != null) {
                            Intent intent = new Intent(getContext(), WebActivity.class);
                            Bundle bundle = new Bundle();
                            bundle.putString("url", serverurl);
                            bundle.putString("title", "在线客服");
                            intent.putExtras(bundle);
                            startActivity(intent);
                        }
                    }
                });
//                }
            } else {
                if (gamedata != null && gamedata.size() != 0) {
                    holder.geme_tv.setText(gamedata.get(position).game_name);
                    int sre = gamedata.get(position).game_id;
                    switch (sre) {

                        case 80:
                            Glide.with(getContext()).load(R.mipmap.mssc).into(holder.game_iv);
                            break;
                        case 50:
                            Glide.with(getContext()).load(R.mipmap.bjsc).into(holder.game_iv);
                            break;
                        case 82:
                            Glide.with(getContext()).load(R.mipmap.msft).into(holder.game_iv);
                            break;
                        case 99:
                            Glide.with(getContext()).load(R.mipmap.xgpm).into(holder.game_iv);
                            break;
                        case 70:
                            Glide.with(getContext()).load(R.mipmap.xglhc).into(holder.game_iv);
                            break;
                        case 81:
                            Glide.with(getContext()).load(R.mipmap.msssc).into(holder.game_iv);
                            break;
                        case 1:
                            Glide.with(getContext()).load(R.mipmap.cqssc).into(holder.game_iv);
                            break;
                        case 4:
                            Glide.with(getContext()).load(R.mipmap.xjssc).into(holder.game_iv);
                            break;
                        case 60:
                            Glide.with(getContext()).load(R.mipmap.gdklsf).into(holder.game_iv);
                            break;
                        case 91:
                            Glide.with(getContext()).load(R.mipmap.msnn).into(holder.game_iv);
                            break;
                        case 90:
                            Glide.with(getContext()).load(R.mipmap.pksnn).into(holder.game_iv);
                            break;
                        case 61:
                            Glide.with(getContext()).load(R.mipmap.cqxync).into(holder.game_iv);
                            break;
                        case 66:
                            Glide.with(getContext()).load(R.mipmap.pcdd).into(holder.game_iv);
                            break;
                        case 65:
                            Glide.with(getContext()).load(R.mipmap.bjklb).into(holder.game_iv);
                            break;
                        case 86:
                            Glide.with(getContext()).load(R.mipmap.msks).into(holder.game_iv);
                            break;
                        case 85:
                            Glide.with(getContext()).load(R.mipmap.xylhc).into(holder.game_iv);
                            break;
                        case 10:
                            Glide.with(getContext()).load(R.mipmap.jsks).into(holder.game_iv);
                            break;
                        case 12:
                            Glide.with(getContext()).load(R.mipmap.gxks).into(holder.game_iv);
                            break;
                        case 13:
                            Glide.with(getContext()).load(R.mipmap.hubks).into(holder.game_iv);
                            break;
                        case 11:
                            Glide.with(getContext()).load(R.mipmap.ahks).into(holder.game_iv);
                            break;
                        case 16:
                            Glide.with(getContext()).load(R.mipmap.gsks).into(holder.game_iv);
                            break;
                        case 15:
                            Glide.with(getContext()).load(R.mipmap.hbks).into(holder.game_iv);
                            break;
                        case 18:
                            Glide.with(getContext()).load(R.mipmap.gzks).into(holder.game_iv);
                            break;
                        case 21:
                            Glide.with(getContext()).load(R.mipmap.gdsyxw).into(holder.game_iv);
                            break;
                        case 112:
                            Glide.with(getContext()).load(R.mipmap.txffc).into(holder.game_iv);
                            break;
                        case 113:
                            Glide.with(getContext()).load(R.mipmap.qqffc).into(holder.game_iv);
                            break;
                        case 801:
                            Glide.with(getContext()).load(R.mipmap.kssc).into(holder.game_iv);
                            break;
                        //快速飞艇
                        case 802:
                            Glide.with(getContext()).load(R.mipmap.ksft).into(holder.game_iv);
                            break;
                        //快速时时彩
                        case 803:
                            Glide.with(getContext()).load(R.mipmap.ksssc).into(holder.game_iv);
                            break;
                        case 804:
                            Glide.with(getContext()).load(R.mipmap.twxyft).into(holder.game_iv);
                            break;
                        case 901:
                            Glide.with(getContext()).load(R.mipmap.sfsc).into(holder.game_iv);
                            break;
                        //快速飞艇
                        case 902:
                            Glide.with(getContext()).load(R.mipmap.sfssc).into(holder.game_iv);
                            break;
                        //快速时时彩
                        case 903:
                            Glide.with(getContext()).load(R.mipmap.jslhc).into(holder.game_iv);
                            break;
                        case 904:
                            Glide.with(getContext()).load(R.mipmap.sflhc).into(holder.game_iv);
                            break;
                        case 55:
                            Glide.with(getContext()).load(R.mipmap.xyft).into(holder.game_iv);
                            break;
                        default:
                            break;
                    }
                    holder.itemView.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            Intent intent = new Intent(getContext(), GameDetailActivityFinal.class);
                            GameDetailConstances.GameId = gamedata.get(position).game_id;
                            GameDetailConstances.GameName = gamedata.get(position).game_name + "";
                            intent.putExtra("gameid", gamedata.get(position).game_id + "");
                            intent.putExtra("gamename", gamedata.get(position).game_name + "");
                            if (Info.user != null) {
                                startActivity(intent);
                            } else {
                                ((BaseActivity) getActivity()).startLogin();
                            }
                        }
                    });
                }
            }
        }

        @Override
        public int getItemCount() {
            try {
                if (gamedata.size() >= 7 && gamedata.size() < 10) {
                    return 9;
                } else if (gamedata.size() >= 10 && gamedata.size() < 13) {
                    return 12;
                } else if (gamedata.size() >= 13) {
                    return 15;
                } else {
                    return gamedata.size() + 2;
                }
            } catch (Exception e) {
                return 0;
            }
        }

        @Override
        public void onItemClick(View view, int position) {

        }

        class MViewHolder extends RecyclerView.ViewHolder {
            TextView geme_tv;
            ImageView game_iv;

            MViewHolder(View itemView) {
                super(itemView);
                geme_tv = (TextView) itemView.findViewById(R.id.geme_tv);
                game_iv = (ImageView) itemView.findViewById(R.id.game_iv);

            }
        }
    }

    ////////////////////////////////////////////右侧游戏/////////////////////////////////////////////////////
    class Adapter1 extends RecyclerView.Adapter<Adapter1.MViewHolder>
            implements OnItemClickListener {
        @Override
        public MViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            return new MViewHolder(LayoutInflater.from(getContext())
                    .inflate(R.layout.game_item, parent, false));

        }

        @Override
        public void onBindViewHolder(final MViewHolder holder, final int position) {
            if (flag == 1) {
                holder.geme_tv.setText(kaiyuantv[position]);
                Glide.with(getContext()).load(kaiyuanimg[position]).into(holder.game_iv);
            }
            if (flag == 2) {
                holder.geme_tv.setText(longchengtv[position]);
                Glide.with(getContext()).load(longchengimg[position]).into(holder.game_iv);
            }
            if (flag == 3) {
                holder.geme_tv.setText(wushuangtv[position]);
                Glide.with(getContext()).load(wushuangimg[position]).into(holder.game_iv);
            }
            if (flag == 4) {
                holder.geme_tv.setText(vgtv[position]);
                Glide.with(getContext()).load(vgiv[position]).into(holder.game_iv);
            }
            /**
             * 	‘token’ =>, //用户token，
             ‘g_id’ => 15， // 接口id  开元 龙成
             ‘tag’ => 1,   //接口游戏id
             ‘doingCode’ => 1， //请求类型 0:登录 1:刷新余额
             */
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (Info.user != null) {
                        myDialog = new AlertDialogIos(getActivity()).builder();
                        myDialog.setGone().setMsg("是否进入游戏").setNegativeButton("取消", R.color.skyblue, new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                myDialog.dismiss();
                            }
                        }).setPositiveButton("确定", R.color.skyblue, new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                myDialog.dismiss();
                                if (flag == 1) {
                                    mPresenter.getkaiyuangame(Info.user.token, "15", kaiyuantag[position], "0");
                                } else if (flag == 2) {
                                    mPresenter.getkaiyuangame(Info.user.token, "16", longchengurl[position], "0");
                                } else if (flag == 3) {
                                    mPresenter.getkaiyuangame(Info.user.token, "17", "", "0");
                                } else if (flag == 4) {
                                    mPresenter.getkaiyuangame(Info.user.token, "18", vgtag[position], "0");
                                }
                            }
                        }).show();


                    } else {
                        ((BaseActivity) getActivity()).startLogin();
                    }

                }
            });

        }

        @Override
        public int getItemCount() {
            if (flag == 1) {
                return kaiyuantv.length;
            } else if (flag == 2) {
                return longchengtv.length;
            } else if (flag == 3) {
                return wushuangtv.length;
            } else if (flag == 4) {
                return vgtv.length;
            } else {
                return 0;
            }

        }

        @Override
        public void onItemClick(View view, int position) {

        }

        class MViewHolder extends RecyclerView.ViewHolder {
            TextView geme_tv;
            ImageView game_iv;

            MViewHolder(View itemView) {
                super(itemView);
                geme_tv = (TextView) itemView.findViewById(R.id.geme_tv);
                game_iv = (ImageView) itemView.findViewById(R.id.game_iv);

            }
        }
    }


    class Adapter2 extends RecyclerView.Adapter<Adapter2.MViewHolder1>
            implements OnItemClickListener {
        @Override
        public MViewHolder1 onCreateViewHolder(ViewGroup parent, int viewType) {
            return new MViewHolder1(LayoutInflater.from(getContext())
                    .inflate(R.layout.gameleibieitem, parent, false));

        }

        @Override
        public void onBindViewHolder(final MViewHolder1 holder, final int position) {
            //开始设置游戏类别按钮和属性

            if (mgamedatas.data.get(position).g_id.equals("15")) {
                holder.gameitem.setText("开元棋牌");
                holder.gameitem.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        flag = 1;
                        url = "15";
                        for (int x = 0; x < mgamedatas.data.size(); x++) {
                            if (x == position) {
                                mgamedatas.data.get(x).ischoose = true;
                            } else {
                                mgamedatas.data.get(x).ischoose = false;
                            }
                        }
                        adapter2.notifyDataSetChanged();
                        adapter1.notifyDataSetChanged();
                    }
                });
            } else if (mgamedatas.data.get(position).g_id.equals("16")) {
                holder.gameitem.setText("龍城游戏");
                holder.gameitem.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        flag = 2;
                        url = "16";
                        for (int x = 0; x < mgamedatas.data.size(); x++) {
                            if (x == position) {
                                mgamedatas.data.get(x).ischoose = true;
                            } else {
                                mgamedatas.data.get(x).ischoose = false;
                            }
                        }
                        adapter2.notifyDataSetChanged();
                        adapter1.notifyDataSetChanged();
                    }
                });
            } else if (mgamedatas.data.get(position).g_id.equals("17")) {
                holder.gameitem.setText("无双棋牌");
                holder.gameitem.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        flag = 3;
                        url = "17";
                        for (int x = 0; x < mgamedatas.data.size(); x++) {
                            if (x == position) {
                                mgamedatas.data.get(x).ischoose = true;
                            } else {
                                mgamedatas.data.get(x).ischoose = false;
                            }
                        }
                        adapter2.notifyDataSetChanged();
                        adapter1.notifyDataSetChanged();
                    }
                });
            } else if (mgamedatas.data.get(position).g_id.equals("18")) {
                holder.gameitem.setText("VG棋牌");
                holder.gameitem.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        flag = 4;
                        url = "18";
                        for (int x = 0; x < mgamedatas.data.size(); x++) {
                            if (x == position) {
                                mgamedatas.data.get(x).ischoose = true;
                            } else {
                                mgamedatas.data.get(x).ischoose = false;
                            }
                        }
                        adapter2.notifyDataSetChanged();
                        adapter1.notifyDataSetChanged();
                    }
                });
            }
            //最后将我们选中的更新
            if (mgamedatas.data.get(position).ischoose) {
                holder.gameitem.setBackgroundResource(R.mipmap.heiseqipai);
                holder.gameitem.setTextColor(getContext().getResources().getColor(R.color.settingbg));
            } else {
                holder.gameitem.setBackgroundResource(R.mipmap.baiseqipai);
                holder.gameitem.setTextColor(getContext().getResources().getColor(R.color.blank));
            }
        }

        @Override
        public int getItemCount() {
            if (mgamedatas != null) {
                if (mgamedatas.data != null) {
                    return mgamedatas.data.size();
                } else {
                    return 0;
                }
            } else {
                return 0;
            }
        }

        @Override
        public void onItemClick(View view, int position) {

        }

        class MViewHolder1 extends RecyclerView.ViewHolder {
            TextView gameitem;

            MViewHolder1(View itemView) {
                super(itemView);
                gameitem = (TextView) itemView.findViewById(R.id.gameitme);
            }
        }
    }

    @Override
    public void onResume() {
        super.onResume();
        if (Info.user == null) {
            loginlin.setVisibility(View.VISIBLE);
            loginlins.setVisibility(View.GONE);
        } else {
            loginlin.setVisibility(View.GONE);
            loginlins.setVisibility(View.VISIBLE);
            if (Info.user.userName != null) {
                youke.setText(Info.user.userName);
            }

        }
    }

    @Override
    protected void ChangeSkin() {
        switch (SkinId) {
            case 17771:
                skinbg.setBackgroundResource(R.mipmap.skin_bg1);
                break;
            case 17772:
                skinbg.setBackgroundResource(R.mipmap.skin_bg2);
                break;
            case 17773:
                skinbg.setBackgroundResource(R.mipmap.skin_bg3);
                break;
            default:
                skinbg.setBackgroundResource(R.mipmap.skin_bg1);
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }


    @Subscribe(threadMode = ThreadMode.MAIN, sticky = true) //在ui线程执行
    public void Event(refreshFragmentEvent messageEvent) {
        mPresenter.getNotices(Info.user.token);
    }

}
